<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>轮播图</title>
</head>
<body>

<div class="layui-container">
    <div class="layui-row">
        <h1 class="layui-col-md-offset5">轮播图管理<h1>
    </div>
    <hr/>
    <button class="layui-btn layui-btn-normal" id="addbtn"><i class="layui-icon">&#xe61f;</i>添加轮播图</button>
    <table class="layui-table" lay-skin="line">
        <thead>
        <tr>
            <th>轮播图</th>
            <th>描述</th>
            <th>商品编号</th>
            <th>商品名称</th>
            <th>操作</th>
        </tr>
        <tr th:each="item,itemStat:${list}">
            <td><img th:src="${item.img}"></td>
            <td><span th:text="${item.mark}"></span></td>
            <td><span th:text="${item.goodId}"></span></td>
            <td><span th:text="${item.goodsName}"></span></td>
            <td><a class="layui-btn layui-btn-normal edit" th:cid="${item.id}">编辑</a>
                <a class="layui-btn layui-btn-danger del" th:cid="${item.id}">删除</a>
            </td>
        </tr>

        </thead>

    </table>
</div>

<script type="text/javascript">

    layui.use(['layer'], function () {
        $ = layui.jquery;
        layer = layui.layer;

        $("#addbtn").click(function () {
            $.ajax({
                url: "/carousel/countCarousel/",
                type: "post",
                asyns: true,
                success: function (data) {
                    if (data.code == 500) {
                        layer.msg(data.msg, {icon: 2});
                    } else {
                        $("#content-body").load("/carousel/goAddPage");
                    }
                }
            });

        });

        $(".edit").click(function () {
            var cid = $(this).attr("cid");
            $("#content-body").load("/carousel/goUpdatePage/" + cid);
        });

        $(".del").click(function () {
            var cid = $(this).attr("cid");
            layer.confirm('真的删除行么', {icon: 2}, function (index) {
                layer.close(index);
                //向服务端发送删除指令
                $.ajax({
                    url: "/carousel/delete",
                    dataType: "json",
                    data: {
                        id: cid
                    },
                    type: "post",
                    success: function (data) {
                        if (data.code == 200) {
                            $(this).parent().parent().html("1");
                            layer.msg(data.msg, {icon: 1});
                        } else {
                            layer.msg(data.msg, {icon: 2});
                        }

                    }
                })
            });
        });


    });


</script>

</body>
</html>